//
// Created by 215609 on 2024/8/7.
//

#ifndef TSAVPLAYER_VIDEODECODER_H
#define TSAVPLAYER_VIDEODECODER_H


#include "BaseDecoder.h"

#include <VideoRender.h>
#include <ImageDef.h>
using namespace std;

class VideoDecoder: public BaseDecoder{
public:
    VideoDecoder(char *url){
        Init(url, AVMEDIA_TYPE_VIDEO);
    }

    ~VideoDecoder(){
        UnInit();
    }




    virtual void OnDecoderReady();
    virtual void OnDecoderDone();
    virtual void OnFrameAvailable(AVFrame *frame);
    int GetVideoWidth()
    {
        return m_VideoWidth;
    }
    int GetVideoHeight()
    {
        return m_VideoHeight;
    }

    void SetVideoRender(VideoRender *videoRender)
    {
        m_VideoRender = videoRender;
    }



private:

    char *url;
    const AVPixelFormat DST_PIXEL_FORMAT = AV_PIX_FMT_RGBA;
    int m_VideoWidth = 0;
    int m_VideoHeight = 0;


    int m_RenderWidth = 0;
    int m_RenderHeight = 0;
    AVFrame *m_RGBAFrame = nullptr;
    uint8_t *m_FrameBuffer = nullptr;
    VideoRender *m_VideoRender = nullptr;

    SwsContext *m_SwsContext = nullptr;
};


#endif //TSAVPLAYER_VIDEODECODER_H
